package com.macro.mall.model;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.macro.mall.common.api.PageReq;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.Transient;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * ti_training实体类
 *
 * @author gaodx
 *
 */
@Data
@ApiModel(description = "专题信息报文",value = "专题信息报文")
public class TiTraining extends PageReq implements Serializable{
	/**id*/
    @ApiModelProperty(value = "id")
	private Integer id; 
	/**培训专题名称*/
	@NotNull(message = "学院id不可为空")
    @ApiModelProperty(value = "学院id")
	private Integer collegeId;
	/**培训专题名称*/
	@NotNull(message = "培训专题名称不可为空")
    @ApiModelProperty(value = "培训专题名称")
	private String name;
	/**培训专题标题*/
    @ApiModelProperty(value = "培训专题标题")
	private String title; 
	/**图片地址*/
    @ApiModelProperty(value = "图片地址")
	private String image; 
	/**专题简介*/
    @NotNull(message = "专题简介不可为空")
    @ApiModelProperty(value = "专题简介")
	private String desc; 
	/**有效时间*/
    @ApiModelProperty(value = "考试开始时间")
	private Date startTime; 
	/**失效时间*/
    @ApiModelProperty(value = "考试结束时间")
	private Date endTime; 
	/**试卷id*/
    @ApiModelProperty(value = "试卷id")
	private Long examId; 
	/**证书图片地址*/
    @ApiModelProperty(value = "证书图片地址")
	private String certificate; 
	/**01-可用 02-不可用*/
    @ApiModelProperty(value = "01-可用 02-不可用")
	private String status;
	/**创建时间*/
    @ApiModelProperty(value = "创建时间")
	private Date createTime; 
	/**修改时间*/
    @ApiModelProperty(value = "修改时间")
	private Date updateTime;

	/**修改时间*/
    @ApiModelProperty(value = "考试状态 00-无考试 01-考试未开始 02-考试开始 03-考试结束")
	private String trainingStatus;

	/**修改时间*/
    @ApiModelProperty(value = "考试是否通过 N-未通过 Y-通过")
	private String through;

	/**开课时间*/
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@ApiModelProperty(value = "开课时间")
	private Date openTime;

	@ApiModelProperty(value = "专题平均分")
	private Integer trainingAvg;

	/***/
	@ApiModelProperty(value = "签到签退列表")
	private List<TiTrainingSignRecord> signList;
	/***/
	@ApiModelProperty(value = "人员配置列表")
	private List<TiTrainingUser> userList;

	/**人员配置*/
	@ApiModelProperty(value = "人员配置 0-所有用户 1-指定")
	private String userAssign;


    /**排序字段, 数字越大越靠前*/
    @ApiModelProperty(value = "排序字段, 数字越大越靠前")
    private Integer sort;



	@Transient
	private String canSee = "no";

    public String getTrainingStatus() {
        long l = System.currentTimeMillis();
        if(null == startTime && null == endTime) {
            this.trainingStatus = "00";
        } else if(startTime.getTime() > l ){
            this.trainingStatus = "01";
        }else if(startTime.getTime() < l && endTime.getTime() > l){
            this.trainingStatus = "02";
        } else if(endTime.getTime() < l) {
            this.trainingStatus = "03";
        }

        return trainingStatus;
    }

    /**
	 * 实例化
	 */
	public TiTraining() {
		super();
	}
	/**
	 * 实例化
	 * 
	 * @param obj
	 */

	public TiTraining(JSONObject obj) {
		this();
		if (obj.get("id") instanceof Number) {
			this.setId(((Number) obj.get("id")).intValue());
		}
		if (obj.get("name") instanceof String) {
			this.setName((String) obj.get("name"));
		}
		if (obj.get("title") instanceof String) {
			this.setTitle((String) obj.get("title"));
		}
		if (obj.get("image") instanceof String) {
			this.setImage((String) obj.get("image"));
		}
		if (obj.get("desc") instanceof String) {
			this.setDesc((String) obj.get("desc"));
		}
		this.setStartTime((Date) obj.get("startTime"));
		this.setEndTime((Date) obj.get("endTime"));
		if (obj.get("examId") instanceof Number) {
			this.setExamId(((Number) obj.get("examId")).longValue());
		}
		if (obj.get("certificate") instanceof String) {
			this.setCertificate((String) obj.get("certificate"));
		}
		if (obj.get("status") instanceof String) {
			this.setStatus((String) obj.get("status"));
		}
		this.setCreateTime((Date) obj.get("createTime"));
		this.setUpdateTime((Date) obj.get("updateTime"));
	}
	
	/**
	 * 将当前对象转换为JsonObject
	 * 
	 * @return
	 */
	public JSONObject toJson() {
		JSONObject result = new JSONObject();
		if (this.getId() != null) {
			result.put("id",this.getId());
		}
		if (this.getName() != null) {
			result.put("name",this.getName());
		}
		if (this.getTitle() != null) {
			result.put("title",this.getTitle());
		}
		if (this.getImage() != null) {
			result.put("image",this.getImage());
		}
		if (this.getDesc() != null) {
			result.put("desc",this.getDesc());
		}
		if (this.getStartTime() != null) {
			result.put("startTime",this.getStartTime());
		}
		if (this.getEndTime() != null) {
			result.put("endTime",this.getEndTime());
		}
		if (this.getExamId() != null) {
			result.put("examId",this.getExamId());
		}
		if (this.getCertificate() != null) {
			result.put("certificate",this.getCertificate());
		}
		if (this.getStatus() != null) {
			result.put("status",this.getStatus());
		}
		if (this.getCreateTime() != null) {
			result.put("createTime",this.getCreateTime());
		}
		if (this.getUpdateTime() != null) {
			result.put("updateTime",this.getUpdateTime());
		}
		return result;
	}


	@Override
	public String toString() {
		return "TiTraining [id=" + id + " , name=" + name + " , title=" + title + " , image=" + image + " , desc=" + desc + " , startTime=" + startTime + " , endTime=" + endTime + " , examId=" + examId + " , certificate=" + certificate + " , status=" + status + " , createTime=" + createTime + " , updateTime=" + updateTime + "  ]";
	
	}
	
	
}
